package vacuum.noSpam;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerListener implements Listener{
	
	private NoSpam ns;

	public PlayerListener(NoSpam ns){
		this.ns = ns;
	}
	
	@EventHandler(priority=EventPriority.MONITOR)
	public void onPlayerJoin(PlayerJoinEvent event)
	{
		String name = event.getPlayer().getName();
		boolean contains = ns.observeList.contains(name.toLowerCase());
		if(ns.whitelist){
			if(contains){
				ns.log("Adding player " + name);
				ns.sd.addPlayer(name.toLowerCase());
			}
		} else {
			if(!contains){
				ns.log("Adding player " + name);
				ns.sd.addPlayer(name.toLowerCase());
			}
		}
	}
	
	@EventHandler(priority=EventPriority.MONITOR)
    public void onPlayerQuit(PlayerQuitEvent event)
    {
            ns.log("Removing player " + event.getPlayer().getName());
            ns.sd.removePlayer(event.getPlayer().getName().toLowerCase());
    }
}
